package com.yunhe.tianhe.rentcars.service.system.impl;



import com.yunhe.tianhe.commons.dto.Pageable;
import com.yunhe.tianhe.commons.util.StringUtils;
import com.yunhe.tianhe.rentcars.dao.system.MemberLevelDao;
import com.yunhe.tianhe.rentcars.entity.system.MemberLevel;
import com.yunhe.tianhe.rentcars.service.system.MemberLevelService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * # @Author: 贾波
 * # @Time: 2017-11-24-下午 4:00
 * # Description:
 */
@Service
public class MemberLevelServiceImpl implements MemberLevelService {
    @Autowired
     private MemberLevelDao memberLevelDao;
    private Pageable<MemberLevel> pageable=new Pageable<>();


    @Override
    public Long save(MemberLevel memberLevel) {
         memberLevelDao.save(memberLevel);
         return memberLevel.getLevelId();
    }

    @Override
    public void delete(Long id) {
    memberLevelDao.delete(id);
    }

    @Override
    public Long update(MemberLevel memberLevel) {
        return memberLevelDao.update(memberLevel);
    }

    @Override
    public MemberLevel findOne(Long id) {
        return memberLevelDao.findOne(id);
    }

    @Override
    public List<MemberLevel> findList() {
        return memberLevelDao.findList();
    }

    @Override
    public Pageable<MemberLevel> findPageList(Long offset, Long limit,String levelName) {
        List<MemberLevel> pageList = memberLevelDao.findPageList(offset, limit,levelName);
        Long count = memberLevelDao.pageCount();
        pageable.setTotal(count);
        pageable.setRows(pageList);
        return pageable;
    }

    public void deleteBatch(String ids) {
        if(StringUtils.notEmpty(ids)){
            String[] idArr = ids.split(",");
            for(String id : idArr) {
                this.delete(Long.valueOf(id));
            }
        }
    }
}
